package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.domain.dao.PaasProcessRichTextDao;
import com.xbongbong.paas.domain.entity.PaasProcessRichTextEntity;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.model.PaasProcessRichTextModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author bomfish
 */
@Service("paasProcessRichTextModel")
public class PaasProcessRichTextModelImpl implements PaasProcessRichTextModel {
    @Resource
    private PaasProcessRichTextDao paasProcessRichTextDao;

    @Override
    public Long insert(PaasProcessRichTextEntity entity) {
        return paasProcessRichTextDao.insert(entity);
    }

    @Override
    public void insertBatch(List<PaasProcessRichTextEntity> list) {
        paasProcessRichTextDao.insertBatch(list);
    }

    @Override
    public List<PaasProcessRichTextEntity> findEntities(Map<String, Object> param) {
        return paasProcessRichTextDao.findEntities(param);
    }

    @Override
    public Integer getEntityCount(Map<String, Object> param) {
        return paasProcessRichTextDao.getEntitiesCount(param);
    }

    @Override
    public void update(PaasProcessRichTextEntity entity) {
        paasProcessRichTextDao.update(entity);
    }

    @Override
    public void updateByTaskId(PaasProcessRichTextEntity entity) {
        Long now = DateTimeUtil.getInt();
        entity.setUpdateTime(now);
        paasProcessRichTextDao.updateByTaskId(entity);
    }

    @Override
    public PaasProcessRichTextEntity getByKey(Long key, String corpid) {
        return paasProcessRichTextDao.getByKey(key, corpid);
    }

    @Override
    public PaasProcessRichTextEntity getByTaskId(Long taskId, String corpid) {
        return paasProcessRichTextDao.getByTaskId(taskId, corpid);
    }

    @Override
    public boolean hasData(Map<String, Object> params) {
        int size = paasProcessRichTextDao.getIdList(params).size();
        return size != 0;
    }

    @Override
    public Integer countData(Map<String, Object> params) {
        return paasProcessRichTextDao.getIdList(params).size();
    }

    @Override
    public void deleteCompelete(String corpid, Long formId, List<Integer> delList, Integer afterDel) {
        Map<String, Object> params = new HashMap<>(BasicConstant.FIVE);
        params.put(StringConstant.CORPID, corpid);
        params.put(StringConstant.FORM_ID, formId);
        params.put(StringConstant.UPDATE_TIME, DateTimeUtil.getInt());
        params.put("delList", delList);
        params.put("afterDel", afterDel);
        paasProcessRichTextDao.deleteComplete(params);
    }

}
